<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>常熟理工问卷系统</title>
    <link rel="stylesheet" th:href="@{/asserts/bootstrap4/css/bootstrap.css}">
    <link rel="stylesheet" th:href="@{/asserts/css/TeacherSystem.css}">
</head>
<body>
<div th:replace="Default::topNav(${username},${account})"></div>
<div th:replace="Default::leftNav('TeacherAuditForm',${userType})"></div>
<div class="container-fluid">
    <div class="unAuditQuestions" th:if="${data}">
        <div class="one_unAudit" th:each="onequestion : ${data}">
            <div class="QuestionId">
                <span>#id:</span>
                <span id="oneQuestion_id" th:text="${onequestion.id}"></span>
            </div>
            <div class="QuestionTitle" title="问卷标题">
                <span th:text="${onequestion.title}"></span>
                <span style="color: red">(待审核)</span>
            </div>
            <div class="QuestionEdit">
                <a class="btn btn-primary" style="color: white"
                   th:href="@{'/PreViewQuestionForm/'+${onequestion.id}}" target="_blank">预览</a>
                <button class="btn btn-success pass">通过</button>
                <button class="btn btn-danger reject">驳回</button>
            </div>
            <div class="clear"></div>
        </div>
    </div>
    <div class="noQuestions" th:if="not ${data}">
        <img th:src="@{asserts/img/noquestion.png}">
        <div>没有需要审核的表单！</div>
    </div>
</div>
</body>
<script th:src="@{/asserts/js/jquery-3.3.1.min.js}"></script>
<script th:src="@{/asserts/js/popper.min.js}"></script>
<script th:src="@{/asserts/bootstrap4/js/bootstrap.js}"></script>
<script th:src="@{/asserts/js/canvas-nest.min.js}"></script>
<script th:replace="Default :: linklist(${userType})"></script>
<script th:if="${userType} eq 'Teacher'">
    $("#AuditForm").click(function () {
        window.location.href = "/TeacherAuditForm?page=1";
    });
</script>
<script type="text/javascript" th:inline="javascript">
    $(".pass").click(function () {
        var the_question_id = $(this).parents(".one_unAudit").find("#oneQuestion_id").text();
        $.ajax({
            type:"POST",
            url:"/TeacherAuditForm/pass/"+the_question_id,
            contentType:"application/json",
            dataType:"json",
            beforeSend(xml){
                return confirm("确定通过审核吗？");
            },
            success:function (data) {
                if (data.code === 200){
                    window.location.href = "/TeacherAuditForm?page=1";
                } else {
                    alert(data.msg);
                }
            },
            error:function (err) {
                alert(err.toString());
            }
        });
    });
    $(".reject").click(function () {
        var the_question_id = $(this).parents(".one_unAudit").find("#oneQuestion_id").text();
        $.ajax({
            type:"POST",
            url:"/TeacherAuditForm/reject/"+the_question_id,
            contentType:"application/json",
            dataType:"json",
            beforeSend(xml){
                return confirm("确定驳回该表单吗？")
            },
            success:function (data) {
                if (data.code === 200){
                    window.location.href = "/TeacherAuditForm?page=1";
                } else {
                    alert(data.msg);
                }
            },
            error:function (err) {
                alert(err.toString());
            }
        });
    });
</script>